<%--
  @author  lk
  DateTime: 2020/4/14 0014 11:37
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.lk.bean.Goods" %>
<%@ page import="java.util.*" %>
<html>
<head>
    <title>商品</title>
</head>
<body>
<%
    Map<Goods, Integer> map = (Map<Goods, Integer>) request.getAttribute("goodsMap");
    //这里将map.entrySet()转换成list
    List<Map.Entry<Goods, Integer>> list = new ArrayList<Map.Entry<Goods, Integer>>(map.entrySet());
    //然后通过比较器来实现排序
    Collections.sort(list, new Comparator<Map.Entry<Goods, Integer>>() {
        @Override
        public int compare(Map.Entry<Goods, Integer> o1, Map.Entry<Goods, Integer> o2) {
            return o2.getValue()-o1.getValue();
        }
    });
%>
<div style="text-align:right;font-size:36px;">
    <a href="cart.jsp">我的购物车</a>
</div>
<table align="center" width="100%">
    <tr>
        <th>商品编号</th>
        <th>商品名称</th>
        <th>商品单价</th>
        <th>商品销量</th>
    </tr>
    <%
            for (Map.Entry<Goods, Integer> entry : list) {
    %>
    <tr align="center">
        <td><%=entry.getKey().getGoodsId() %>
        </td>
        <td><a href="detail.jsp?id=<%=entry.getKey().getGoodsId()%>"><%=entry.getKey().getGoodsName() %>
        </a></td>
        <td><%=entry.getKey().getGoodsPrice() %>
        </td>
        <td><%= entry.getValue()%>
        </td>
    </tr>
    <%} %>
    <div style="text-align:center;font-size:  36px;">
        <a href="index.jsp">回首页</a>
    </div>
</table>
</body>
</html>
